package com.yangquan.ayuan.synchronizedTest;

/**
 * synchronized 对代码块加锁
 * 锁住的是括号里面的 lock 对象
 */
public class SynchronizedBlockExample {
    private final Object lock = new Object();

    public void method() {
        // 非同步代码
        System.out.println("Non-synchronized code");

        // 同步代码块
        synchronized (lock) {
            System.out.println("Synchronized code block");
        }
    }


    public static void main(String[] args) {
        SynchronizedBlockExample synchronizedBlockExample = new SynchronizedBlockExample();
        synchronizedBlockExample.method();
    }
}